package cn.jbolt.admin.demotable;
import cn.jbolt.core.cache.JBoltCache;
import com.jfinal.aop.Aop;
import cn.jbolt.admin.demotable.model.DemoTable;

public class DemoTableCache extends JBoltCache {
    public static final DemoTableCache me = new DemoTableCache();
    DemoTableService service = Aop.get(DemoTableService.class);
    private static final String TYPE_NAME = "tb_demo_table";
    public String getCacheTypeName() {
        return TYPE_NAME;
    }

    /**
     * 通过ID 获取
     * @param id
     * @return
     */
    public DemoTable get(Long id) {
        return service.findById(id);
    }
    /**
     * 通过SN 获取
     * @param sn
     * @return
     */
    public DemoTable getBySn(String sn) {
        return service.getCacheByKey(sn);
    }

    /**
     * 通过ID 获取Name
     * @param id
     * @return
     */
    public String getName(Long id) {
        DemoTable obj = get(id);
        return obj == null ? null : obj.getName();
    }

    /**
     * 通过SN 获取Name
     * @param sn
     * @return
     */
    public String getNameBySn(String sn) {
        DemoTable obj = getBySn(sn);
        return obj == null ? null : obj.getName();
    }

}

